import apis from "../services/SituationApi";

export default {
  namespace: "situationList",
  state: {
    STList: [],
    totalCount: 0,
    loading: false,
    delErrCode: "-1",
    delErrMsg: "",
    departList: []
  },
  // subscriptions: {
  //   setup({ dispatch, history }) {
  //     // ...
  //   }
  // },
  effects: {
    *getSituationList({ payload }, { call, put }) {
      yield put({
        type: "put/putloading",
        payload: true
      });
      const res = yield call(apis.getSituationList, payload);
      const { datas, totalCount } = res;
      yield put({
        type: "get/getstList",
        payload: datas
      });
      yield put({
        type: "put/putloading",
        payload: false
      });
      yield put({
        type: "put/puttotal",
        payload: totalCount
      });
    },
    *delSecen({ payload }, { call, put }) {
      const res = yield call(apis.delSecen, payload);
      const { errCode, errMsg } = res;
      yield put({
        type: "put/putcode",
        payload: errCode
      });
      yield put({
        type: "put/putErr",
        payload: errMsg
      });
    },
    *departData({ payload }, { call, put }) {
      const res = yield call(apis.departData, payload);
      const { datas } = res;
      yield put({
        type: "put/putdepart",
        payload: datas
      });
    }
  },
  reducers: {
    "get/getstList": (state, { payload }) => ({
      ...state,
      STList: payload
    }),
    "put/putloading": (state, { payload }) => ({
      ...state,
      loading: payload
    }),
    "put/puttotal": (state, { payload }) => ({
      ...state,
      totalCount: payload
    }),
    "put/putcode": (state, { payload }) => ({
      ...state,
      delErrCode: payload
    }),
    "put/putErr": (state, { payload }) => ({
      ...state,
      delErrMsg: payload
    }),
    "put/putdepart": (state, { payload }) => ({
      ...state,
      departList: payload
    })
  }
};
